package services;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;

import org.apache.commons.collections.MultiHashMap;
import org.apache.commons.collections.MultiMap;
//import org.apache.xmlrpc.server.PropertyHandlerMapping;
//import org.apache.xmlrpc.server.XmlRpcServer;
//import org.apache.xmlrpc.webserver.WebServer;
import org.hibernate.Session;

import util.HibernateUtil;
import util.ListObject;
import util.SQLiteUtil;
import util.Util;
import util.XMLParserServerUtil;

import dao.BacSiDAO;
import dao.BaiVietDAO;
import dao.BenhDAO;
import dao.CauHoiTrucTuyenDAO;
import dao.ChuDeDAO;
import dao.ChuDeKhacDAO;
import dao.ChuyenKhoaDAO;
import dao.DAOFactory;
import dao.DiaDiemYTeDAO;
import dao.LoaiBenhDAO;
import dao.LoaiDiaDiemYTeDAO;
import dao.LoaiThietBiYTeDAO;
import dao.LoaiThuocDAO;
import dao.NguoiDungDAO;
import dao.NhomNguoiDungDAO;
import dao.ThietBiYTeDAO;
import dao.ThongTinDBDAO;
import dao.ThuocDAO;
import dao.YKienBanDocDAO;
import dao.hibernate.HibernateDAOFactory;

import model.BacSi;
import model.BaiViet;
import model.Benh;
import model.CauHoiTrucTuyen;
import model.ChuDe;
import model.ChuDeKhac;
import model.ChuyenKhoa;
import model.DiaDiemYTe;
import model.GenerallyObject;
import model.LoaiBenh;
import model.LoaiDiaDiemYTe;
import model.LoaiThietBiYTe;
import model.LoaiThuoc;
import model.NguoiDung;
import model.NhomNguoiDung;
import model.ThietBiYTe;
import model.ThongTinDB;
import model.Thuoc;
import model.YKienBanDoc;

public class HealthSystemServicesProvider {
	DAOFactory daoFactory = DAOFactory.instance(HibernateDAOFactory.class);
	NguoiDungDAO nguoiDungDAO = daoFactory.getNguoiDungDAO();
	CauHoiTrucTuyenDAO cauHoiTrucTuyenDAO = daoFactory.getCauHoiTrucTuyenDAO();
	NhomNguoiDungDAO nhomNguoiDungDAO = daoFactory.getNhomNguoiDungDAO();
	BaiVietDAO baiVietDAO = daoFactory.getBaiVietDAO();
	ChuDeDAO chuDeDAO = daoFactory.getChuDeDAO();
	BenhDAO benhDAO = daoFactory.getBenhDAO();
	ThuocDAO thuocDAO = daoFactory.getThuocDAO();
	DiaDiemYTeDAO diaDiemYTeDAO = daoFactory.getDiaDiemYTeDAO();
	BacSiDAO bacSiDAO = daoFactory.getBacSiDAO();
	ThietBiYTeDAO thietBiYTeDAO = daoFactory.getThietBiYTeDAO();
	ChuDeKhacDAO chuDeKhacDAO = daoFactory.getChuDeKhacDAO();
	LoaiBenhDAO loaiBenhDAO = daoFactory.getLoaiBenhDAO();
	LoaiThuocDAO loaiThuocDAO = daoFactory.getLoaiThuocDAO();
	LoaiDiaDiemYTeDAO loaiDiaDiemYTeDAO = daoFactory.getLoaiDiaDiemYTeDAO();
	LoaiThietBiYTeDAO loaiThietBiYTeDAO = daoFactory.getLoaiThietBiYTeDAO();
	ChuyenKhoaDAO chuyenKhoaDAO = daoFactory.getChuyenKhoaDAO();
	YKienBanDocDAO yKienBanDocDAO = daoFactory.getYKienBanDocDAO();
	ThongTinDBDAO thongTinDBDAO = daoFactory.getThongTinDBDAO();

	Session session = HibernateUtil.getCurrentSession();

	@SuppressWarnings("unchecked")
	public String findAllTop30Benh() {
		session.getTransaction().begin();
		List<Benh> list = benhDAO.findAllTop30();
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	/*-------------------------------NGUOI DUNG-------------------*/
	public boolean saveNewPassUser(String idNguoiDung, String password) {
		session.getTransaction().begin();
		boolean result = false;
		session.getTransaction().begin();
		NguoiDung nguoiDung = nguoiDungDAO.findById(idNguoiDung, false);
		nguoiDung.setMatKhau(password);

		try {
			session.update(nguoiDung);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}

	public boolean saveNewInfoUser(String idNguoiDung, String hoTen,
			String email) {
		session.getTransaction().begin();
		boolean result = false;
		NguoiDung nguoiDung = nguoiDungDAO.findById(idNguoiDung, false);
		nguoiDung.setHoTen(hoTen);
		nguoiDung.setEmail(email);
		try {
			session.update(nguoiDung);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findAllNguoiDung() {
		session.getTransaction().begin();
		List<NguoiDung> list = nguoiDungDAO.findAll();
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	public String findNguoiDungById(String id) {
		session.getTransaction().begin();
		NguoiDung nguoiDung = nguoiDungDAO.findById(id, true);
		String result = XMLParserServerUtil.marshalObject(nguoiDung);
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findAllNguoiDungByIdNhomNguoiDung(String id) {
		session.getTransaction().begin();
		List<NguoiDung> list = nguoiDungDAO.findByIdNhomNguoiDungLike(id);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findAllNhomNguoiDung() {
		session.getTransaction().begin();
		List<NhomNguoiDung> list = nhomNguoiDungDAO.findAll();
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	public boolean createNormalUser(String idNguoiDung, String matKhau,
			String hoTen, String email) {
		session.getTransaction().begin();
		boolean result = false;
		NguoiDung nguoiDung = null;
		if (nguoiDungDAO.findById(idNguoiDung, false) != null)
			result = false;
		else if (nguoiDungDAO.findByEmail(email) != null)
			result = false;
		else {
			NhomNguoiDung nhomNguoiDung = nhomNguoiDungDAO.findById(
					NhomNguoiDung.THANH_VIEN, false);
			if (nhomNguoiDung != null) {
				nguoiDung = new NguoiDung(idNguoiDung, matKhau, nhomNguoiDung,
						hoTen, email);
				try {
					session.save(nguoiDung);
					result = true;
				} catch (Exception e) {
					return false;
				}
			}
		}
		session.getTransaction().commit();
		return result;
	}

	public boolean createUser(String idNguoiDung, String matKhau,
			String idNhomNguoiDung, String hoTen, String email) {
		session.getTransaction().begin();
		boolean result = false;
		NhomNguoiDung nhomND = nhomNguoiDungDAO
				.findById(idNhomNguoiDung, false);
		if (nhomND != null) {
			NguoiDung nguoiDung = null;
			if (nguoiDungDAO.findById(idNguoiDung, false) != null)
				result = false;
			else if (nguoiDungDAO.findByEmail(email) != null)
				result = false;
			else {
				nguoiDung = new NguoiDung(idNguoiDung, matKhau, nhomND, hoTen,
						email);
				try {
					session.save(nguoiDung);
					result = true;
				} catch (Exception e) {
					return false;
				}
			}
		}
		session.getTransaction().commit();
		return result;
	}

	public String checkLogin(String username, String password) {
		session.getTransaction().begin();
		NguoiDung nguoiDung = nguoiDungDAO.checkLogin(username, password);
		String result = XMLParserServerUtil.marshalObject(nguoiDung);
		session.getTransaction().commit();
		return result;
	}

	public boolean updateNguoiDung(String idNguoiDung, String matKhau,
			String idNhomNguoiDung, String hoTen, String email) {
		boolean result = false;
		session.getTransaction().begin();
		NguoiDung nguoiDung = nguoiDungDAO.findById(idNguoiDung, false);
		NhomNguoiDung nhomNguoiDung = nhomNguoiDungDAO.findById(
				idNhomNguoiDung, false);
		nguoiDung.setMatKhau(matKhau);
		nguoiDung.setNhomNguoiDung(nhomNguoiDung);
		nguoiDung.setHoTen(hoTen);
		nguoiDung.setEmail(email);
		try {
			session.update(nguoiDung);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}
	
	public boolean updateNguoiDung(String idNguoiDung, String matKhauCu, String matKhauMoi,
			String idNhomNguoiDung, String hoTen, String email) {
		boolean result = false;
		session.getTransaction().begin();
		NguoiDung nguoiDung = nguoiDungDAO.findById(idNguoiDung, false);
		if (nguoiDung.getMatKhau().equalsIgnoreCase(matKhauCu)) {
			NhomNguoiDung nhomNguoiDung = nhomNguoiDungDAO.findById(
					idNhomNguoiDung, false);
			nguoiDung.setMatKhau(matKhauMoi);
			nguoiDung.setNhomNguoiDung(nhomNguoiDung);
			nguoiDung.setHoTen(hoTen);
			nguoiDung.setEmail(email);
			try {
				session.update(nguoiDung);
				result = true;
			} catch (Exception e) {
				e.printStackTrace();
				result = false;
			}
		} else
			result = false;
		session.getTransaction().commit();
		return result;
	}

	public boolean deleteNguoiDung(String idNguoiDung) {
		boolean result = false;
		session.getTransaction().begin();
		NguoiDung nguoiDung = nguoiDungDAO.findById(idNguoiDung, false);
		try {
			session.delete(nguoiDung);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findNguoiDungByCriteria(String criteria, String keyWord) {
		session.getTransaction().begin();
		List<NguoiDung> list = nguoiDungDAO.findByOneCondition(criteria,
				keyWord);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	/*--------------------------CAU HOI TRUC TUYEN----------------------------*/
	@SuppressWarnings("unchecked")
	public String findAllCauHoiTrucTuyen() {
		session.getTransaction().begin();
		List<CauHoiTrucTuyen> list = cauHoiTrucTuyenDAO.findAll();
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findAllCauHoiTrucTuyenChuaTraLoi() {
		session.getTransaction().begin();
		List<CauHoiTrucTuyen> list = cauHoiTrucTuyenDAO.findAllChuaTraLoi();
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}
	
	@SuppressWarnings("unchecked")
	public String findAllCauHoiTrucTuyenChuaTraLoiByIdNguoiTraLoi(String idNguoiTraLoi) {
		session.getTransaction().begin();
		List<CauHoiTrucTuyen> list = cauHoiTrucTuyenDAO.findAllChuaTraLoiByIdNguoiTraLoi(idNguoiTraLoi);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	public String findCauHoiTrucTuyenById(int id) {
		session.getTransaction().begin();
		CauHoiTrucTuyen cauHoi = cauHoiTrucTuyenDAO.findById((long) id, true);
		String result = XMLParserServerUtil.marshalObject(cauHoi);
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findCauHoiTrucTuyenByNguoiHoi(String userId) {
		session.getTransaction().begin();
		List<CauHoiTrucTuyen> list = cauHoiTrucTuyenDAO
				.findByIdNguoiHoi(userId);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	public boolean traLoiCauHoiTrucTuyen(int idCauHoi, String idNguoiTraLoi,
			String noiDung) {
		boolean result = false;
		session.getTransaction().begin();
		CauHoiTrucTuyen cauHoi = cauHoiTrucTuyenDAO.findById((long) idCauHoi,
				false);
		if (cauHoi != null) {
			NguoiDung nguoiTraLoi = nguoiDungDAO.findById(idNguoiTraLoi, false);
			cauHoi.setTraLoi(noiDung);
			cauHoi.setNguoiTraLoi(nguoiTraLoi);
			cauHoi.setNgayTraLoi(new Date());
			cauHoi.setDaXem(false);
			session.save(cauHoi);
			result = true;
		}
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findTraLoiChuaXemByNguoiHoi(String userId) {
		session.getTransaction().begin();
		List<CauHoiTrucTuyen> list = cauHoiTrucTuyenDAO
				.findUnreadByIdNguoiHoi(userId);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	public boolean setReadCauHoiTrucTuyen(int id) {
		boolean result = false;
		session.getTransaction().begin();
		CauHoiTrucTuyen cauHoi = cauHoiTrucTuyenDAO.findById((long) id, false);
		if (cauHoi != null) {
			cauHoi.setDaXem(true);
			session.save(cauHoi);
			result = true;
		}
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findCauHoiTrucTuyenByNguoiHoiLike(String userId) {
		session.getTransaction().begin();
		List<CauHoiTrucTuyen> list = cauHoiTrucTuyenDAO
				.findByIdNguoiHoiLike(userId);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findCauHoiTrucTuyenByNguoiTraLoi(String userId) {
		session.getTransaction().begin();
		List<CauHoiTrucTuyen> list = cauHoiTrucTuyenDAO
				.findByIdNguoiTraLoi(userId);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findCauHoiTrucTuyenByNguoiTraLoiLike(String userId) {
		session.getTransaction().begin();
		List<CauHoiTrucTuyen> list = cauHoiTrucTuyenDAO
				.findByIdNguoiTraLoiLike(userId);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findCauHoiTrucTuyenByCriteria(String criteria, String keyWord) {
		session.getTransaction().begin();
		List<CauHoiTrucTuyen> list = cauHoiTrucTuyenDAO.findByOneCondition(
				criteria, keyWord);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	public boolean addCauHoiTrucTuyen(String chuDe, String tieuDe,
			String noiDung, String idNguoiHoi, String idNguoiTraLoi) {
		session.getTransaction().begin();
		boolean result = false;
		ChuDe myChuDe = null;
		List<ChuDe> dsChuDe = chuDeDAO.findByNameLike(chuDe);
		if (dsChuDe != null && dsChuDe.size() > 0)
			myChuDe = dsChuDe.get(0);
		NguoiDung nguoiHoi = nguoiDungDAO.findById(idNguoiHoi, false);
		NguoiDung nguoiTraLoi = nguoiDungDAO.findById(idNguoiTraLoi, false);
		if (myChuDe != null && nguoiHoi != null) {
			Date ngayHoi = new Date();
			CauHoiTrucTuyen cauHoi = new CauHoiTrucTuyen(myChuDe, tieuDe,
					noiDung, nguoiHoi, ngayHoi, nguoiTraLoi);
			session.save(cauHoi);
			result = true;
		}
		session.getTransaction().commit();
		return result;
	}
	
	public boolean deleteCauHoiTrucTuyen(int idCauHoi) {
		boolean result = false;
		session.getTransaction().begin();
		CauHoiTrucTuyen cauHoiTrucTuyen = cauHoiTrucTuyenDAO.findById((long)idCauHoi, false);
		try {
			session.delete(cauHoiTrucTuyen);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}

	/*-------------------------------CHU DE CHA-----------------*/
	@SuppressWarnings("unchecked")
	public String findAllChuDeCha() {
		session.getTransaction().begin();
		List<ChuDe> list = chuDeDAO.findAllMainTopic();
		// List<ChuDe> list1 = new ArrayList<ChuDe>();
		// list1.add(list.get(0));
		// list = list1;
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	public String findChuDeChaByLoai(String loai) {
		session.getTransaction().begin();
		ChuDe chude = chuDeDAO.findChuDeChaByLoai(loai);
		String result = XMLParserServerUtil.marshalObject(chude);
		session.getTransaction().commit();
		return result;
	}

	/*-------------------------------LOAI BENH-----------------*/
	public boolean editLoaiBenh(int idLoaiBenh, String tenLoaiBenhMoi,
			int idChuyenKhoa) {
		session.getTransaction().begin();
		boolean result = false;
		session.getTransaction().begin();
		LoaiBenh loaiBenh = loaiBenhDAO.findById((long) idLoaiBenh, true);
		ChuyenKhoa chuyenKhoa = chuyenKhoaDAO.findById((long) idChuyenKhoa,
				false);
		loaiBenh.setChuyenKhoa(chuyenKhoa);
		loaiBenh.setTenLoaiBenh(tenLoaiBenhMoi);
		try {
			session.update(loaiBenh);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}

	public boolean addLoaiBenh(String tenLoaiBenh, int idChuyenKhoa) {
		session.getTransaction().begin();
		boolean result = false;
		ChuyenKhoa chuyenKhoa = chuyenKhoaDAO.findById((long) idChuyenKhoa,
				false);
		LoaiBenh loaibenh = new LoaiBenh();
		loaibenh.setTenLoaiBenh(tenLoaiBenh);
		loaibenh.setChuyenKhoa(chuyenKhoa);
		try {
			session.save(loaibenh);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findAllLoaiBenh() {
		session.getTransaction().begin();
		List<LoaiBenh> list = loaiBenhDAO.findAll();
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	public String findLoaiBenhById(int id) {
		session.getTransaction().begin();
		LoaiBenh loaiBenh = (LoaiBenh) loaiBenhDAO.findById((long) id, false);
		String result = XMLParserServerUtil.marshalObject(loaiBenh);
		session.getTransaction().commit();
		return result;
	}

	public boolean deleteLoaiBenh(int idLoaiBenh) {
		session.getTransaction().begin();
		boolean result = false;
		LoaiBenh loaiBenh = loaiBenhDAO.findById((long) idLoaiBenh, false);
		try {
			session.delete(loaiBenh);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}

	/*-----------------------------------BENH---------------------------------*/
	public boolean editBenh(int idBenh, int idLoaiBenh, String nguyenNhan,
			String trieuChung, String chanDoan, String cachChuaTriTayY,
			String cachChuaTriDongY, String phongChongBenh) {
		session.getTransaction().begin();
		boolean result = false;
		Benh benh = benhDAO.findById((long) idBenh, false);
		LoaiBenh loaiBenh = loaiBenhDAO.findById((long) idLoaiBenh, false);
		benh.setLoaiBenh(loaiBenh);
		benh.setNguyenNhan(nguyenNhan);
		benh.setTrieuChung(trieuChung);
		benh.setChanDoan(chanDoan);
		benh.setCachChuaTriTayY(cachChuaTriTayY);
		benh.setCachChuaTriDongY(cachChuaTriDongY);
		benh.setPhongChongBenh(phongChongBenh);
		try {
			session.update(benh);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findAllBenh() {
		session.getTransaction().begin();
		List<Benh> list = benhDAO.findAll();
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findAllBenhByIdLoaiBenh(int id) {
		session.getTransaction().begin();
		List<Benh> list = benhDAO.findAllBenhByIdLoaiBenh((long) id);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	public String findBenhById(int id) {
		session.getTransaction().begin();
		Benh benh = (Benh) benhDAO.findById((long) id, false);
		String result = XMLParserServerUtil.marshalObject(benh);
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findLoaiBenhByCriteria(String criteria, String keyWord) {
		session.getTransaction().begin();
		List<LoaiBenh> list = loaiBenhDAO.findByOneCondition(criteria, keyWord);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	public boolean deleteBenh(int idBenh) {
		boolean result = false;
		session.getTransaction().begin();
		Benh benh = benhDAO.findById((long) idBenh, false);
		try {
			session.delete(benh);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}

	public boolean addBenh(int idLoaiBenh, String tenBenh, String nguyenNhan,
			String trieuChung, String chanDoan, String cachChuaTriTayY,
			String cachChuaTriDongY, String phongChongBenh, String idDsThuoc,
			String idDsDiaDiemYTe) {
		session.getTransaction().begin();
		boolean result = false;

		// lấy idThuoc
		Set<Integer> idThuocs = new HashSet<Integer>();
		StringTokenizer st = new StringTokenizer(idDsThuoc, ", ");
		while (st.hasMoreElements()) {
			idThuocs.add(Integer.parseInt(st.nextElement().toString()));

		}
		// truy vấn ds Thuốc
		Set<Thuoc> dsThuoc = new HashSet<Thuoc>();
		for (Integer id : idThuocs) {
			Thuoc thuoc = thuocDAO.findById((long) id, false);
			dsThuoc.add(thuoc);
		}
		// lấy idDiaDiemYTe
		Set<Integer> idDiaDiaDiemYTes = new HashSet<Integer>();
		st = new StringTokenizer(idDsDiaDiemYTe, ", ");
		while (st.hasMoreElements()) {
			idDiaDiaDiemYTes.add(Integer.parseInt(st.nextElement().toString()));

		}
		// truy vấn ds DiaDiemYTe
		Set<DiaDiemYTe> dsDiaDiemYTeChuyen = new HashSet<DiaDiemYTe>();
		for (Integer id : idDiaDiaDiemYTes) {
			DiaDiemYTe ddyt = diaDiemYTeDAO.findById((long) id, false);
			dsDiaDiemYTeChuyen.add(ddyt);
		}

		Benh benh = null;
		LoaiBenh loaiBenh = loaiBenhDAO.findById((long) idLoaiBenh, false);
		ChuDe chuDeCha = chuDeDAO.findByName("Bệnh");
		if (loaiBenh != null) {
			benh = new Benh(tenBenh, chuDeCha, loaiBenh, nguyenNhan,
					trieuChung, chanDoan, cachChuaTriTayY, cachChuaTriDongY,
					phongChongBenh);
			// benh.setDsThuocChua(dsThuoc);
			for (Thuoc t : dsThuoc) {
				benh.addThuocChua(t);
			}
			// benh.setDsDiaDiemYTeChuyen(dsDiaDiemYTeChuyen);
			for (DiaDiemYTe diaDiemYTe : dsDiaDiemYTeChuyen) {
				benh.addDiaDiemYTe(diaDiemYTe);
			}
			try {
				session.save(benh);
				result = true;
			} catch (Exception e) {
				return false;
			}
		}
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findBenhByCriteria(String criteria, String keyWord) {
		session.getTransaction().begin();
		List<Benh> list = benhDAO.findByOneCondition(criteria, keyWord);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	public boolean editBenh(int idBenh, int idLoaiBenh, String ten, String nguyenNhan,
			String trieuChung, String chanDoan, String cachChuaTriTayY,
			String cachChuaTriDongY, String phongChongBenh, String idDsThuoc,
			String idDsDiaDiemYTe) {
		session.getTransaction().begin();
		boolean result = false;

		// lấy idThuoc
		Set<Integer> idThuocs = new HashSet<Integer>();
		StringTokenizer st = new StringTokenizer(idDsThuoc, ", ");
		while (st.hasMoreElements()) {
			idThuocs.add(Integer.parseInt(st.nextElement().toString()));

		}
		// truy vấn ds Thuốc
		Set<Thuoc> dsThuoc = new HashSet<Thuoc>();
		for (Integer id : idThuocs) {
			Thuoc thuoc = thuocDAO.findById((long) id, false);
			dsThuoc.add(thuoc);
		}
		// lấy idDiaDiemYTe
		Set<Integer> idDiaDiaDiemYTes = new HashSet<Integer>();
		st = new StringTokenizer(idDsDiaDiemYTe, ", ");
		while (st.hasMoreElements()) {
			idDiaDiaDiemYTes.add(Integer.parseInt(st.nextElement().toString()));

		}
		// truy vấn ds DiaDiemYTe
		Set<DiaDiemYTe> dsDiaDiemYTeChuyen = new HashSet<DiaDiemYTe>();
		for (Integer id : idDiaDiaDiemYTes) {
			DiaDiemYTe ddyt = diaDiemYTeDAO.findById((long) id, false);
			dsDiaDiemYTeChuyen.add(ddyt);
		}

		Benh benh = benhDAO.findById((long) idBenh, false);
		LoaiBenh loaiBenh = loaiBenhDAO.findById((long) idLoaiBenh, false);
		benh.setTenChuDe(ten);
		benh.setLoaiBenh(loaiBenh);
		benh.setNguyenNhan(nguyenNhan);
		benh.setTrieuChung(trieuChung);
		benh.setChanDoan(chanDoan);
		benh.setCachChuaTriTayY(cachChuaTriTayY);
		benh.setCachChuaTriDongY(cachChuaTriDongY);
		benh.setPhongChongBenh(phongChongBenh);
		benh.setDsThuocChua(dsThuoc);
		benh.setDsDiaDiemYTeChuyen(dsDiaDiemYTeChuyen);
		try {
			session.update(benh);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}

	/*-----------------------------------DIA DIEM Y TE--------------------*/
	@SuppressWarnings("unchecked")
	public String findAllDiaDiemYTe() {
		session.getTransaction().begin();
		List<DiaDiemYTe> list = diaDiemYTeDAO.findAll();
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	public String findDiaDiemYTeById(int id) {
		session.getTransaction().begin();
		DiaDiemYTe diaDiemYTe = (DiaDiemYTe) diaDiemYTeDAO.findById((long) id,
				false);
		String result = XMLParserServerUtil.marshalObject(diaDiemYTe);
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findDiaDiemYTeByLoaiDiaDiem(String diaDiem) {
		session.getTransaction().begin();
		List<DiaDiemYTe> list = diaDiemYTeDAO
				.findDiaDiemYTeByLoaiDiaDiem(diaDiem);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findDiaDiemYTeByIdLoaiDiaDiem(int id) {
		session.getTransaction().begin();
		List<DiaDiemYTe> list = diaDiemYTeDAO.findDiaDiemYTeByIdLoaiDiaDiem(id);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findDiaDiemYTeByCriteria(String criteria, String keyWord) {
		session.getTransaction().begin();
		List<DiaDiemYTe> list = diaDiemYTeDAO.findByOneCondition(criteria,
				keyWord);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}
	
	public boolean deleteDiaDiemYTe(int id) {
		boolean result = false;
		session.getTransaction().begin();
		DiaDiemYTe diaDiemYTe = diaDiemYTeDAO.findById((long) id, false);
		try {
			for (Benh benh : diaDiemYTe.getDsBenhChuyen()) {
				benh.removeDiaDiemYTe(diaDiemYTe);
				session.saveOrUpdate(benh);
			}
			session.delete(diaDiemYTe);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}
				
	public boolean editDiaDiemYTe(int idDDYT, String tenDDYT, String dsIDChuyenKhoa, String dsIDBacSi, String dsIDBenhChuyen, 
			int idLoaiDDYT, String diaChi, String sdt, String thongTin, String viDo, String kinhDo) {
		session.getTransaction().begin();
		boolean result = false;
		session.getTransaction().begin();
		DiaDiemYTe ddyt = diaDiemYTeDAO.findById((long) idDDYT, false);
		LoaiDiaDiemYTe loaiDDYT = loaiDiaDiemYTeDAO.findById((long) idLoaiDDYT, false);
		
		// select Ds Chuyên Khoa
		Set<Integer> idChuyenKhoas = new HashSet<Integer>();
		StringTokenizer st = new StringTokenizer(dsIDChuyenKhoa, ", ");
		while (st.hasMoreTokens()) {
			idChuyenKhoas.add(Integer.parseInt(st.nextToken()));
		}

		Set<ChuyenKhoa> dsChuyenKhoa = new HashSet<ChuyenKhoa>();
		for (Integer id1 : idChuyenKhoas) {
			ChuyenKhoa chuyenKhoa = chuyenKhoaDAO.findById((long) id1, false);
			dsChuyenKhoa.add(chuyenKhoa);
		}
		
		// parse and select Ds Bac Si
		Set<Integer> idBacSis = new HashSet<Integer>();
		 st = new StringTokenizer(dsIDBacSi, ", ");
		while (st.hasMoreTokens()) {
			idBacSis.add(Integer.parseInt(st.nextToken()));

		}

		Set<BacSi> dsBacSi = new HashSet<BacSi>();
		for (Integer id1 : idBacSis) {
			BacSi bacSi = bacSiDAO.findById((long) id1, false);
			dsBacSi.add(bacSi);
		}
		
		// parse and select Ds benh Chuyen
		Set<Integer> idBenhChuyens = new HashSet<Integer>();
		 st = new StringTokenizer(dsIDBenhChuyen, ", ");
		while (st.hasMoreTokens()) {
			idBenhChuyens.add(Integer.parseInt(st.nextToken()));
		}
		
		Set<Benh> dsBenhCu = ddyt.getDsBenhChuyen();
		if (dsBenhCu == null)
			dsBenhCu = new HashSet<Benh>();
		
		for (Benh benh : dsBenhCu) {
			benh.removeDiaDiemYTe(ddyt);
			session.saveOrUpdate(benh);
		}
		
		Set<Benh> dsBenhChuyen = new HashSet<Benh>();
		for (Integer id1 : idBenhChuyens) {
			Benh benh = benhDAO.findById((long) id1, false);
			dsBenhChuyen.add(benh);
		}
		
		ddyt.setDsBenhChuyen(dsBenhChuyen);
		
		for (Benh benh : dsBenhChuyen) {
			benh.addDiaDiemYTe(ddyt);
			session.saveOrUpdate(benh);
		}
		
//		-----------------
		double kinhDoDouble = 0;
		double viDoDouble = 0;
		try {
			kinhDoDouble = Double.parseDouble(kinhDo);
			viDoDouble = Double.parseDouble(viDo);
		} catch (Exception e) {
			
		}
		
		ddyt.setTenChuDe(tenDDYT);
		ddyt.setLoaiDiaDiemYTe(loaiDDYT);
		ddyt.setDiaChi(diaChi);
		ddyt.setThongTin(thongTin);
		ddyt.setSoDienThoai(sdt);
		ddyt.setKinhDo(kinhDoDouble);
		ddyt.setViDo(viDoDouble);
		ddyt.setDsChuyenKhoa(dsChuyenKhoa);
		
		try {
			session.update(ddyt);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}

	public boolean addDiaDiemYTe(String tenDDYT,String dsIDChuyenKhoa, String dsIDBacSi, String dsIDBenhChuyen, 
			int idLoaiDDYT, String diaChi, String sdt, String thongTin, String viDo, String kinhDo) {
		session.getTransaction().begin();
		boolean result = false;
		LoaiDiaDiemYTe loaiDDYT = loaiDiaDiemYTeDAO.findById((long) idLoaiDDYT, false);
		
		// select Ds Chuyên Khoa
		Set<Integer> idChuyenKhoas = new HashSet<Integer>();
		StringTokenizer st = new StringTokenizer(dsIDChuyenKhoa, ", ");
		while (st.hasMoreTokens()) {
			idChuyenKhoas.add(Integer.parseInt(st.nextToken()));
		}

		Set<ChuyenKhoa> dsChuyenKhoa = new HashSet<ChuyenKhoa>();
		for (Integer id1 : idChuyenKhoas) {
			ChuyenKhoa chuyenKhoa = chuyenKhoaDAO.findById((long) id1, false);
			dsChuyenKhoa.add(chuyenKhoa);
		}
		
		// parse and select Ds Bac Si
		Set<Integer> idBacSis = new HashSet<Integer>();
		 st = new StringTokenizer(dsIDBacSi, ", ");
		while (st.hasMoreTokens()) {
			idBacSis.add(Integer.parseInt(st.nextToken()));
		}

		Set<BacSi> dsBacSi = new HashSet<BacSi>();
		for (Integer id1 : idBacSis) {
			BacSi bacSi = bacSiDAO.findById((long) id1, false);
			dsBacSi.add(bacSi);
		}
		
		// parse and select Ds benh Chuyen
		Set<Integer> idBenhChuyens = new HashSet<Integer>();
		 st = new StringTokenizer(dsIDBenhChuyen, ", ");
		while (st.hasMoreTokens()) {
			idBenhChuyens.add(Integer.parseInt(st.nextToken()));
		}

		Set<Benh> dsBenhChuyen = new HashSet<Benh>();
		for (Integer id1 : idBenhChuyens) {
			Benh benh = benhDAO.findById((long) id1, false);
			dsBenhChuyen.add(benh);
		}
//		-----------------
		double kinhDoDouble = 0;
		double viDoDouble = 0;
		try {
			kinhDoDouble = Double.parseDouble(kinhDo);
			viDoDouble = Double.parseDouble(viDo);
		} catch (Exception e) {
			
		}
		
		ChuDe chuDeCha = chuDeDAO.findByName("Địa điểm y tế");
		DiaDiemYTe ddyt = new DiaDiemYTe(tenDDYT, chuDeCha, loaiDDYT, thongTin, diaChi, sdt, viDoDouble, kinhDoDouble);
		
		ddyt.setDsChuyenKhoa(dsChuyenKhoa);
		
		for (Benh b : dsBenhChuyen) {
			Benh benh = benhDAO.findById(b.getIdChuDe(), true);
			benh.addDiaDiemYTe(ddyt);
			session.saveOrUpdate(benh);
		}
		
		try {
			session.save(ddyt);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}

	/*-------------------------------LOAI DIA DIEM Y TE--------------------*/

	@SuppressWarnings("unchecked")
	public String findAllLoaiDiaDiemYTe() {
		session.getTransaction().begin();
		List<LoaiDiaDiemYTe> list = loaiDiaDiemYTeDAO.findAll();
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	/*-----------------------------------CHUYEN KHOA--------------------*/
	@SuppressWarnings("unchecked")
	public String findAllChuyenKhoa() {
		session.getTransaction().begin();
		List<ChuyenKhoa> list = chuyenKhoaDAO.findAll();
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	public String findChuyenKhoaById(int id) {
		session.getTransaction().begin();
		ChuyenKhoa chuyenKhoa = (ChuyenKhoa) chuyenKhoaDAO.findById((long) id,
				false);
		String result = XMLParserServerUtil.marshalObject(chuyenKhoa);
		session.getTransaction().commit();
		return result;
	}

	/*------------------------------------BAC SI---------------------*/
	@SuppressWarnings("unchecked")
	public String findAllBacSi() {
		session.getTransaction().begin();
		List<BacSi> list = bacSiDAO.findAll();
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	public String findBacSiById(int id) {
		session.getTransaction().begin();
		BacSi bacSi = (BacSi) bacSiDAO.findById((long) id, false);
		System.out.println("uu"+ bacSi.getDsBenhChuyen().size());
		String result = XMLParserServerUtil.marshalObject(bacSi);
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findAllBacSiByCriteria(String criteria, String keyword) {
		session.getTransaction().begin();
		List<BacSi> list = bacSiDAO.findByOneCondition(criteria, keyword);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	public boolean addBacSi(String tenChuDe, int idChuyenKhoa,
			int idNoiCongTac, String ngaySinh, int thamNien, String diaChi,
			String soDienThoai, String idDsBenh, String idNguoiDung) {
		session.getTransaction().begin();
		
		System.out.println(tenChuDe + ", " + idChuyenKhoa + ", " + idNoiCongTac + ", " + ngaySinh + ", " + thamNien + ", " + diaChi + ", " + soDienThoai + ", " + idDsBenh + ", " + idNguoiDung);

		boolean result = false;
		Set<Integer> idBenhs = new HashSet<Integer>();
		StringTokenizer st = new StringTokenizer(idDsBenh, ", ");
		while (st.hasMoreElements()) {
			idBenhs.add(Integer.parseInt(st.nextElement().toString()));
		}

		Set<Benh> dsBenh = new HashSet<Benh>();
		for (Integer id : idBenhs) {
			Benh benh = benhDAO.findById((long) id, false);
			dsBenh.add(benh);
		}

		ChuDe chuDeCha = chuDeDAO.findChuDeChaByLoai("Bác sĩ");
		ChuyenKhoa ck = chuyenKhoaDAO.findById((long) idChuyenKhoa, false);
		DiaDiemYTe dd = diaDiemYTeDAO.findById((long) idNoiCongTac, false);
		Date ns = Util.convertStringToDate(ngaySinh);
		
		BacSi bs = null;
		if (chuDeCha != null && ck != null && dd != null) {
			bs = new BacSi(tenChuDe, chuDeCha, ck, dd, ns, thamNien, diaChi,
					soDienThoai, idNguoiDung);
			for (Benh b : dsBenh) {
				b.addBacSi(bs);
				session.saveOrUpdate(b);
			}
		}
		
		try {
			session.save(bs);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}

	public boolean updateBacSi(int idChuDe, String tenChuDe, int idChuyenKhoa,
			int idNoiCongTac, String ngaySinh, int thamNien, String diaChi,
			String soDienThoai,String idDsBenh) {
		session.getTransaction().begin();
		
		BacSi bs = bacSiDAO.findById((long) idChuDe, false);

		boolean result = false;
		Set<Integer> idBenhs = new HashSet<Integer>();
		StringTokenizer st = new StringTokenizer(idDsBenh, ", ");
		while (st.hasMoreElements()) {
			idBenhs.add(Integer.parseInt(st.nextElement().toString()));
		}
		
		Set<Benh> dsBenhCu = new HashSet<Benh>();
		
		for (Benh b : dsBenhCu) {
			b.removeBacSi(bs);
			session.saveOrUpdate(b);
		}
		
		Set<Benh> dsBenh = new HashSet<Benh>();
		for (Integer id : idBenhs) {
			Benh benh = benhDAO.findById((long) id, false);
			dsBenh.add(benh);
		}
		
		bs.setDsBenhChuyen(dsBenh);
		
		for (Benh b : dsBenh) {
			b.addBacSi(bs);
			session.saveOrUpdate(b);
		}
		
		ChuyenKhoa ck = chuyenKhoaDAO.findById((long) idChuyenKhoa, false);
		DiaDiemYTe dd = diaDiemYTeDAO.findById((long) idNoiCongTac, false);
		Date ns = Util.convertStringToDate(ngaySinh);
		
		bs.setIdChuDe(idChuDe);
		bs.setTenChuDe(tenChuDe);
		bs.setChuyenKhoa(ck);
		bs.setNoiCongTac(dd);
		bs.setNgaySinh(ns);
		bs.setThamNien(thamNien);
		bs.setDiaChi(diaChi);
		bs.setSoDienThoai(soDienThoai);
		bs.setDsBenhChuyen(dsBenh);

		try {
			session.update(bs);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}

	public boolean deleteBacSi(int id) {
		boolean result = false;
		session.getTransaction().begin();
		BacSi bs = bacSiDAO.findById((long) id, false);
		try {
			for (Benh b : bs.getDsBenhChuyen()) {
				b.removeBacSi(bs);
				session.saveOrUpdate(b);
			}
			session.delete(bs);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}

	/*-------------------------------THUOC-------------------------------*/
	@SuppressWarnings("unchecked")
	public String findAllThuoc() {
		session.getTransaction().begin();
		List<Thuoc> list = thuocDAO.findAll();
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	public String findThuocById(int id) {
		session.getTransaction().begin();
		Thuoc thuoc = (Thuoc) thuocDAO.findById((long) id, false);
		String result = XMLParserServerUtil.marshalObject(thuoc);
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findAllThuocByIdLoaiThuoc(int id) {
		session.getTransaction().begin();
		List<Thuoc> list = thuocDAO.findAllThuocByIdLoaiThuoc((long) id);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findAllLoaiThuoc() {
		session.getTransaction().begin();
		List<LoaiThuoc> list = loaiThuocDAO.findAll();
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	public String findLoaiThuocById(int id) {
		session.getTransaction().begin();
		LoaiThuoc loaiThuoc = (LoaiThuoc) loaiThuocDAO.findById((long) id,
				false);
		String result = XMLParserServerUtil.marshalObject(loaiThuoc);
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findAllLoaiThuocByCriteria(String criteria, String keyWord) {
		session.getTransaction().begin();
		List<LoaiThuoc> list = loaiThuocDAO.findByOneCondition(criteria,
				keyWord);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findAllThuocByCriteria(String criteria, String keyWord) {
		session.getTransaction().begin();
		List<Thuoc> list = thuocDAO.findByOneCondition(criteria, keyWord);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	public boolean addLoaiThuoc(String ten) {
		boolean result = false;
		session.getTransaction().begin();
		LoaiThuoc loaiThuoc = new LoaiThuoc(ten);

		try {
			session.save(loaiThuoc);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}

	public boolean addThuoc(String tenChuDe, int idLoaiThuoc, String thanhPhan,
			String chiDinh, String chongChiDinh, String nhaSanXuat,
			String quyCachDongGoi, boolean thamKhaoBacSi, String idDsBenh) {
		boolean result = false;
		session.getTransaction().begin();

		Set<Integer> idBenhs = new HashSet<Integer>();
		StringTokenizer st = new StringTokenizer(idDsBenh, ", ");
		while (st.hasMoreElements()) {
			idBenhs.add(Integer.parseInt(st.nextElement().toString()));
		}

		Set<Benh> dsBenh = new HashSet<Benh>();
		for (Integer id : idBenhs) {
			Benh benh = benhDAO.findById((long) id, false);
			dsBenh.add(benh);
		}

		ChuDe chuDeCha = chuDeDAO.findChuDeChaByLoai("Thuốc");
		LoaiThuoc loaiThuoc = loaiThuocDAO.findById((long) idLoaiThuoc, false);
		Thuoc thuoc = new Thuoc(tenChuDe, chuDeCha, loaiThuoc, thanhPhan,
				chiDinh, chongChiDinh, nhaSanXuat, quyCachDongGoi,
				thamKhaoBacSi);
		for (Benh b : dsBenh) {
			Benh benh = benhDAO.findById(b.getIdChuDe(), true);
			benh.addThuocChua(thuoc);
			session.saveOrUpdate(benh);
		}

		try {
			session.save(thuoc);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}

	public boolean updateLoaiThuoc(int id, String ten) {
		boolean result = false;
		session.getTransaction().begin();
		LoaiThuoc loaiThuoc = loaiThuocDAO.findById((long) id, false);
		loaiThuoc.setTenLoaiThuoc(ten);
		try {
			session.update(loaiThuoc);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}

	public boolean updateThuoc(int id, String tenChuDe, int idLoaiThuoc,
			String thanhPhan, String chiDinh, String chongChiDinh,
			String nhaSanXuat, String quyCachDongGoi, boolean thamKhaoBacSi,
			String idDsBenh) {
		boolean result = false;
		session.getTransaction().begin();

		Set<Integer> idBenhs = new HashSet<Integer>();
		StringTokenizer st = new StringTokenizer(idDsBenh, ", ");
		while (st.hasMoreTokens()) {
			idBenhs.add(Integer.parseInt(st.nextToken()));
		}

		Set<Benh> dsBenhMoi = new HashSet<Benh>();
		for (Integer id1 : idBenhs) {
			Benh benh = benhDAO.findById((long) id1, false);
			dsBenhMoi.add(benh);
		}

		LoaiThuoc loaiThuoc = loaiThuocDAO.findById((long) idLoaiThuoc, false);
		Thuoc thuoc = thuocDAO.findById((long) id, false);
		Set<Benh> dsBenhCu = thuoc.getDsBenh();
		if (dsBenhCu == null)
			dsBenhCu = new HashSet<Benh>();
		thuoc.setTenChuDe(tenChuDe);
		thuoc.setLoaiThuoc(loaiThuoc);
		thuoc.setThanhPhan(thanhPhan);
		thuoc.setChiDinh(chiDinh);
		thuoc.setChongChiDinh(chongChiDinh);
		thuoc.setNhaSanXuat(nhaSanXuat);
		thuoc.setQuyCachDongGoi(quyCachDongGoi);
		thuoc.setThamKhaoBacSi(thamKhaoBacSi);
		
		for (Benh benh : dsBenhCu) {
			benh.removeThuocChua(thuoc);
			session.saveOrUpdate(benh);
		}
		
		thuoc.setDsBenh(dsBenhMoi);
		
		for (Benh benh : dsBenhMoi) {
			benh.addThuocChua(thuoc);
			session.saveOrUpdate(benh);
		}
		
		try {
			session.update(thuoc);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}

	public boolean deleteLoaiThuoc(int id) {
		boolean result = false;
		session.getTransaction().begin();
		LoaiThuoc loaiThuoc = loaiThuocDAO.findById((long) id, false);
		try {
			session.delete(loaiThuoc);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}

	public boolean deleteThuoc(int id) {
		boolean result = false;
		session.getTransaction().begin();
		Thuoc thuoc = thuocDAO.findById((long) id, false);
		try {
			for (Benh benh : thuoc.getDsBenh()) {
				benh.removeThuocChua(thuoc);
				session.saveOrUpdate(benh);
			}
			session.delete(thuoc);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}

	/*-----------------------------------TRANG THIET BI Y TE-----------------*/
	@SuppressWarnings("unchecked")
	public String findAllThietBiYTe() {
		session.getTransaction().begin();
		List<ThietBiYTe> list = thietBiYTeDAO.findAll();
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	public String findThietBiYTeById(int id) {
		session.getTransaction().begin();
		ThietBiYTe thietBiYTe = (ThietBiYTe) thietBiYTeDAO.findById((long) id,
				false);
		String result = XMLParserServerUtil.marshalObject(thietBiYTe);
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findAllThietBiByCriteria(String criteria, String keyWord) {
		session.getTransaction().begin();
		List<ThietBiYTe> list = thietBiYTeDAO.findByOneCondition(criteria,
				keyWord);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}
	
	@SuppressWarnings("unchecked")
	public String findAllThietBiYTeByIdLoai(int idLoaiThietBiYTe) {
		session.getTransaction().begin();
		List<ThietBiYTe> list = thietBiYTeDAO.findByIdLoaiThietBiYTe(idLoaiThietBiYTe);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	public boolean addThietBiYTe(String ten, int idLoaiThietBiYTe, String congDung, String cachDung,
			String nhaSX, String URLHinh) {
		boolean result = false;
		session.getTransaction().begin();
		ChuDe chuDeCha = chuDeDAO.findChuDeChaByLoai("Thiết bị y tế");
		LoaiThietBiYTe loaiThietBiYTe = loaiThietBiYTeDAO.findById((long)idLoaiThietBiYTe, false);
		if (chuDeCha != null && loaiThietBiYTe != null) {
			ThietBiYTe thietBi = new ThietBiYTe(loaiThietBiYTe, ten, chuDeCha, congDung, cachDung,
					nhaSX, URLHinh);

			try {
				session.save(thietBi);
				result = true;
			} catch (Exception e) {
				e.printStackTrace();
				result = false;
			}
		}
		
		session.getTransaction().commit();
		return result;
	}

	public boolean updateThietBiYTe(int id, String ten, int idLoaiThietBiYTe, String congDung,
			String cachDung, String nhaSX, String URLHinh) {
		boolean result = false;
		session.getTransaction().begin();
		ThietBiYTe thietBi = thietBiYTeDAO.findById((long) id, false);
		LoaiThietBiYTe loaiThietBiYTe = loaiThietBiYTeDAO.findById((long)idLoaiThietBiYTe, false);
		if (loaiThietBiYTe != null)
			thietBi.setLoaiThietBiYTe(loaiThietBiYTe);
		thietBi.setIdChuDe(id);
		thietBi.setTenChuDe(ten);
		thietBi.setCongDung(congDung);
		thietBi.setCachDung(cachDung);
		thietBi.setNhaSanXuat(nhaSX);
		thietBi.setURLHinh(URLHinh);
		try {
			session.update(thietBi);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}

	public boolean deleteThietBiYTe(int id) {
		boolean result = false;
		session.getTransaction().begin();
		ThietBiYTe thietBI = thietBiYTeDAO.findById((long) id, false);
		try {
			session.delete(thietBI);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}
	
	/*-------------------------------LOAI THIET BI Y TE--------------------*/

	@SuppressWarnings("unchecked")
	public String findAllLoaiThietBiYTe() {
		session.getTransaction().begin();
		List<LoaiThietBiYTe> list = loaiThietBiYTeDAO.findAll();
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	/*------------------------------------CHU DE KHAC----------------*/
	@SuppressWarnings("unchecked")
	public String findAllChuDeKhac() {
		session.getTransaction().begin();
		List<ChuDeKhac> list = chuDeKhacDAO.findAll();
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	public String findChuDeKhacById(int id) {
		session.getTransaction().begin();
		ChuDeKhac chuDeKhac = (ChuDeKhac) chuDeKhacDAO.findById((long) id,
				false);
		String result = XMLParserServerUtil.marshalObject(chuDeKhac);
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findChuDeKhacByTenLike(String keyword) {
		session.getTransaction().begin();
		List<ChuDeKhac> list = chuDeKhacDAO.findByTenChuDeKhacLike(keyword);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	public String findChuDeKhacByLoai(String loai) {
		session.getTransaction().begin();
		ChuDe chude = chuDeKhacDAO.findChuDeChaByLoai(loai);
		String result = XMLParserServerUtil.marshalObject(chude);
		session.getTransaction().commit();
		return result;
	}

	/*----------------------------------BAI VIET-------------------------*/
	@SuppressWarnings("unchecked")
	public String findAllBaiViet() {
		session.getTransaction().begin();
		List<BaiViet> list = baiVietDAO.findAllSimple();
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findAllBaiVietChuDeKhac() {
		session.getTransaction().begin();
		List<BaiViet> list = baiVietDAO.findAllBaiVietChuDeKhac();
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	public String findBaiVietById(int id) {
		session.getTransaction().begin();
		BaiViet baiViet = baiVietDAO.findById((long) id, false);
		String result = XMLParserServerUtil.marshalObject(baiViet);
		session.getTransaction().commit();
		return result;
	}

	public boolean updateSoLanXemBaiViet(int id) {
		boolean result = false;
		session.getTransaction().begin();
		BaiViet baiViet = baiVietDAO.findById((long) id, false);
		baiViet.setSoLanXem(baiViet.getSoLanXem() + 1);
		try {
			session.update(baiViet);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findAllBaiVietByIdLoaiChuDeKhac(int idLoaiChuDeKhac) {
		session.getTransaction().begin();
		List<BaiViet> list = baiVietDAO
				.findAllBaiVietByIdLoaiChuDeKhac((long) idLoaiChuDeKhac);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findAllBaiVietByLoaiChuDe(String loaiChuDe) {
		session.getTransaction().begin();
		List<BaiViet> list = baiVietDAO.findAllBaiVietMoiByLoaiChuDe(loaiChuDe);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	public boolean binhLuanBaiViet(int idBaiViet, String idNguoiDung,
			String noiDung) {
		boolean result = false;
		session.getTransaction().begin();
		BaiViet baiViet = baiVietDAO.findById((long) idBaiViet, false);
		NguoiDung nguoiGui = nguoiDungDAO.findById(idNguoiDung, false);
		YKienBanDoc yKien = new YKienBanDoc(baiViet, nguoiGui, noiDung,
				new Date());
		try {
			session.save(yKien);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findBaiVietMoi(int soBaiViet) {
		session.getTransaction().begin();
		List<BaiViet> list = baiVietDAO.findBaiVietMoi(soBaiViet);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findAllBaiVietMoiByLoaiChuDeKhac(String loaiChuDeKhac,
			int soBaiViet) {
		session.getTransaction().begin();
		List<BaiViet> list = baiVietDAO.findAllBaiVietMoiByLoaiChuDeKhac(
				loaiChuDeKhac, soBaiViet);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}
	
	@SuppressWarnings("unchecked")
	public String findAllBaiVietMoiByLoaiChuDeKhac(String loaiChuDeKhac, String nameLike,
			int soBaiViet) {
		session.getTransaction().begin();
		List<BaiViet> list = baiVietDAO.findAllBaiVietMoiByLoaiChuDeKhac(
				loaiChuDeKhac, nameLike, soBaiViet);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findBaiVietXemNhieu(int soBaiViet) {
		session.getTransaction().begin();
		List<BaiViet> list = baiVietDAO.findBaiVietXemNhieu(soBaiViet);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findBaiVietByIdChuDe(int idChuDe, int soBaiViet) {
		session.getTransaction().begin();
		List<BaiViet> list = baiVietDAO
				.findBaiVietByIdChuDe(idChuDe, soBaiViet);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findBaiVietByCriteria(String criteria, String keyWord) {
		session.getTransaction().begin();
		List<BaiViet> list = baiVietDAO.findByOneCondition(criteria, keyWord);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}
	
	public boolean addBaiViet(String tenChuDe, String tieuDe, String tomTat,
			String noiDung, String URLHinh, String idNguoiDang,
			String tuKhoaTimKiem) {
		session.getTransaction().begin();
		boolean result = false;
		ChuDe chuDe = null;
		List<ChuDe> dsChuDe = chuDeDAO.findByNameLike(tenChuDe);
		if (dsChuDe != null && dsChuDe.size() > 0)
			chuDe = dsChuDe.get(0);
		NguoiDung nguoiDang = nguoiDungDAO.findById(idNguoiDang, false);
		if (chuDe != null && nguoiDang != null) {
			Date ngayDang = new Date();
			BaiViet baiViet = new BaiViet(chuDe, tieuDe, tomTat, URLHinh,
					ngayDang, nguoiDang, noiDung, 0, tuKhoaTimKiem);
			session.save(baiViet);
			result = true;
		}
		session.getTransaction().commit();
		return result;
	}

	public boolean updateBaiViet(int idBaiViet, String tenChuDe, String tieuDe,
			String tomTat, String noiDung, String URLHinh, String ngayDang,
			String idNguoiDang, String tuKhoaTimKiem) {
		boolean result = false;
		session.getTransaction().begin();
		BaiViet baiViet = baiVietDAO.findById((long) idBaiViet, false);
		List<ChuDe> dsChuDe = chuDeDAO.findByNameLike(tenChuDe);
		ChuDe chuDe = null;
		if (dsChuDe != null && dsChuDe.size() > 0)
			chuDe = dsChuDe.get(0);
		NguoiDung nguoiDang = nguoiDungDAO.findById(idNguoiDang, false);
		baiViet.setChuDe(chuDe);
		baiViet.setTieuDe(tieuDe);
		baiViet.setTomTat(tomTat);
		baiViet.setNoiDung(noiDung);
		baiViet.setURLHinh(URLHinh);
		baiViet.setNgayDang(Util.convertStringToDate(ngayDang));
		baiViet.setNguoiDang(nguoiDang);
		baiViet.setTuKhoaTimKiem(tuKhoaTimKiem);
		try {
			session.update(baiViet);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}

	public boolean deleteBaiViet(int idBaiViet) {
		boolean result = false;
		session.getTransaction().begin();
		BaiViet baiViet = baiVietDAO.findById((long) idBaiViet, false);
		try {
			session.delete(baiViet);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findBaiVietByIdNguoiDang(String idNguoiDang) {
		session.getTransaction().begin();
		List<BaiViet> list = baiVietDAO.findByIdNguoiDang(idNguoiDang);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findAllYKienBanDocByIdBaiViet(int id) {
		session.getTransaction().begin();
		List<YKienBanDoc> list = yKienBanDocDAO
				.findAllYKienBanDocByIdBaiViet((long) id);
		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	/*---------------------------------DATABASE------------------------------*/

	public byte[] updateDatabase() {
		byte[] result = new byte[] {};
		try {
			File dbFile = new File(Util.SQLITE_DB_FOLDER + Util.SQLITE_DB_FILENAME);
			if (! dbFile.exists())
				createSQLiteDB();
			result = Util.getBytesFromFile(dbFile);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public boolean checkDatabaseVersion(int version) {
		session.getTransaction().begin();
		ThongTinDB thongTinDB = thongTinDBDAO.findById(1l, false);
		session.getTransaction().commit();
		if (thongTinDB != null && thongTinDB.getPhienBan() > version)
			return true;
		else
			return false;
	}

	public boolean checkDatabaseSize(int databaseSize) {
		int actualSize = 0;
		try {
			File dbFile = new File(Util.SQLITE_DB_FOLDER + Util.SQLITE_DB_FILENAME);
			if (dbFile.exists()) {
				FileInputStream fis = new FileInputStream(dbFile);
				actualSize = fis.available();
				System.out.println("Remote file size: " + databaseSize);
				System.out.println("Actual file size: " + actualSize);
				if (databaseSize == actualSize)
					return true;
				else
					return false;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return false;
	}
	
	public boolean createSQLiteDB() {
		boolean result = false;
		try {
			Util.updateDatabaseVersion("Cập nhật thông tin đầy đủ hơn");
			result = SQLiteUtil.createSQLiteDB();
		} catch (Exception e) {
			result = false;
			e.printStackTrace();
		}
		return result;
	}

	/*-----------------------------------SEARCH-------------------------------*/
	@SuppressWarnings("unchecked")
	public String findAllByKeyWord(String keyWord) {
		session.getTransaction().begin();

		List<GenerallyObject> list = new ArrayList<GenerallyObject>();

		List<BacSi> listBacSi = bacSiDAO.findByTenBacSiLike(keyWord);
		list.addAll(Util.convertBacSiListToGenerallyObjectList(listBacSi));

		List<LoaiBenh> listLoaiBenh = loaiBenhDAO.findByTenLoaiBenh(keyWord);
		list.addAll(Util.convertLoaiBenhListToGenerallyObjectList(listLoaiBenh));

		List<LoaiThuoc> listLoaiThuoc = loaiThuocDAO
				.findByTenLoaiThuoc(keyWord);
		list.addAll(Util
				.convertLoaiThuocListToGenerallyObjectList(listLoaiThuoc));

		List<Benh> listBenh = benhDAO.findByTenBenhLike(keyWord);
		list.addAll(Util.convertBenhListToGenerallyObjectList(listBenh));

		List<Thuoc> listThuoc = thuocDAO.findByTenThuoc(keyWord);
		list.addAll(Util.convertThuocListToGenerallyObjectList(listThuoc));

		List<DiaDiemYTe> listDiaDiemYTe = diaDiemYTeDAO
				.findByTenDiaDiemLike(keyWord);
		list.addAll(Util
				.convertDiaDiemYTeListToGenerallyObjectList(listDiaDiemYTe));

		List<BaiViet> listBaiViet = baiVietDAO.findByTieuDeLike(keyWord);
		list.addAll(Util.convertBaiVietListToGenerallyObjectList(listBaiViet));

		List<ThietBiYTe> listThietBi = thietBiYTeDAO.findByTenChuDe(keyWord);
		list.addAll(Util
				.convertThietBiYTeListToGenerallyObjectList(listThietBi));

		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

	@SuppressWarnings("unchecked")
	public String findByManyKeyWords(String type, String condition) {
		session.getTransaction().begin();

		List<String> keyPairs = new ArrayList<String>();
		MultiMap conditions = new MultiHashMap();
		StringTokenizer st = new StringTokenizer(condition, ",");
		while (st.hasMoreTokens()) {
			keyPairs.add(st.nextToken().trim());
		}

		for (String keyPair : keyPairs) {
			StringTokenizer s = new StringTokenizer(keyPair, ":");
			String criteria;
			String key;
			while (s.hasMoreTokens()) {
				criteria = s.nextToken().trim();
				key = s.nextToken().trim();
				conditions.put(criteria, key);
			}
		}

		List<GenerallyObject> list = new ArrayList<GenerallyObject>();

		if (type.equalsIgnoreCase("bacSi")) {
			List<BacSi> listBacSi = bacSiDAO.findByManyConditions(conditions);
			list.addAll(Util.convertBacSiListToGenerallyObjectList(listBacSi));
		}

		else if (type.equalsIgnoreCase("loaiBenh")) {
			List<LoaiBenh> listLoaiBenh = loaiBenhDAO
					.findByManyConditions(conditions);
			list.addAll(Util
					.convertLoaiBenhListToGenerallyObjectList(listLoaiBenh));
		}

		else if (type.equalsIgnoreCase("loaiThuoc")) {
			List<LoaiThuoc> listLoaiThuoc = loaiThuocDAO
					.findByManyConditions(conditions);
			;
			list.addAll(Util
					.convertLoaiThuocListToGenerallyObjectList(listLoaiThuoc));
		}

		else if (type.equalsIgnoreCase("benh")) {
			List<Benh> listBenh = benhDAO.findByManyConditions(conditions);
			;
			list.addAll(Util.convertBenhListToGenerallyObjectList(listBenh));
		}

		else if (type.equalsIgnoreCase("thuoc")) {
			List<Thuoc> listThuoc = thuocDAO.findByManyConditions(conditions);
			;
			list.addAll(Util.convertThuocListToGenerallyObjectList(listThuoc));
		}

		else if (type.equalsIgnoreCase("diaDiemYTe")) {
			List<DiaDiemYTe> listDiaDiemYTe = diaDiemYTeDAO
					.findByManyConditions(conditions);
			;
			list.addAll(Util
					.convertDiaDiemYTeListToGenerallyObjectList(listDiaDiemYTe));
		}

		else if (type.equalsIgnoreCase("baiViet")) {
			List<BaiViet> listBaiViet = baiVietDAO
					.findByManyConditions(conditions);
			;
			list.addAll(Util
					.convertBaiVietListToGenerallyObjectList(listBaiViet));
		}

		else if (type.equalsIgnoreCase("thietBiYTe")) {
			List<ThietBiYTe> listThietBi = thietBiYTeDAO
					.findByManyConditions(conditions);
			;
			list.addAll(Util
					.convertThietBiYTeListToGenerallyObjectList(listThietBi));
		}

		String result = XMLParserServerUtil.marshalListObject(new ListObject(
				list));
		session.getTransaction().commit();
		return result;
	}

//	public static void main(String[] args) {
//		try {
//			WebServer webServer = new WebServer(8989);
//			XmlRpcServer xmlRpcServer = webServer.getXmlRpcServer();
//			PropertyHandlerMapping phm = new PropertyHandlerMapping();
//			phm.addHandler("HealthSystem", HealthSystemServicesProvider.class);
//
//			xmlRpcServer.setHandlerMapping(phm);
//			webServer.start();
//			System.out.println("Health System Server is started!");
//		} catch (Exception e) {
//			e.printStackTrace();
//			System.out.println("Health System Server can't start!");
//		}
//	}
}
